#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTcpSocket>
#include <QHostAddress>
#include <QDir>
#include <QFileDialog>
#include <qbuffer.h>
#include <QThread>
#include<Winsock2.h>
#include <QVector>
namespace Ui {
class MainWindow;
class MyThread;
class Common;
class OP;
}

typedef struct _Jp{
unsigned int file_size;
unsigned int send_size;
unsigned int sigl_block;
unsigned int seek;
unsigned int waveid;
char filename[900];
}JpData;
static unsigned long hassend=0;
class Common{
public:
    static void send_size(int size,QTcpSocket *tcpsocket);
    static void send_string(QString content,QTcpSocket *tcpsocket);
    static void send_data(QByteArray content,QTcpSocket *tcpsocket);

};
class OP{
public:
static const char OP_FILE=0x0011;    //发送文件操作
static const char OP_NUMBER=0x0022;   //发送数字操作
static const char OP_STRING=0x0033;   //发送字符串操作
static const char OP_NIL=0x0044;    //空操作
static const char OP_CLOSE=0x0055;   //终止连接
};
class MyThread :public QThread{
    Q_OBJECT
    private:
        void run();
        bool stoped=true;
        QByteArray content;
        QTcpSocket *tcpsocket;
        QString hostip="192.168.2.3";
        int port=1122;
        int block=1000;
        int read_size=0;
        int start_seek=0;
        QByteArray convertJpData(JpData jdata);
    public:
        void stop();
        void on();
        int init_socket();
        void close_socket();
        int readfile(QString filename);
        void setReadInof(int seek,int readcount);
        void send_op(char op);
    private slots:
        void recv();



};
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();
    void on_pushButton_3_clicked();
    void on_pushButton_4_clicked();


private:
    Ui::MainWindow *ui;
    QImage image;
    QString filename;
    void socket_start();
    void socket_stop();
    void socket_close();
    void socket_sendfile();
    QVector<MyThread *> thread;
};



#endif // MAINWINDOW_H
